package com.plane;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;

public class Bullet extends Sprite {
    public Bullet(Hero hero, int xStep) {
        this.width = 6;
        this.height = 14;
        this.xStep = xStep;
        this.yStep = -7;
        this.x = hero.x + hero.width / 2 - width / 2;
        this.y = hero.y - this.height;
        try {
            image = ImageIO.read(Bullet.class.getResourceAsStream("bullet.png"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void move(ArrayList bullets) {
        this.x += xStep;
        this.y += yStep;
        if (this.y < 0) {
            bullets.remove(this);
        }
    }

    public void paint(Graphics gTmp, GamePanel gp) {
        gTmp.drawImage(image, x, y, gp);
    }
}
